package entity

import com.alibaba.fastjson2.JSONObject
import util.FindNode.Companion.parseChildNodes

data class Node(
    val node_id: String,
    val node_alarm: Int,
    val node_name: String,
    val node_code: String,
    val node_seq: Int,
    val node_type: Int,
    val sampl_time: String,
    val nb_sn: String?,
    val nb_imei: String?,
    val nb_device_id: String?,
    val node_path: String,
    val delay: Int,
    var child_nodes: List<Node>?
) {
    constructor(jsonObject: JSONObject) : this(
        jsonObject.getString("node_id"),
        jsonObject.getIntValue("node_alarm"),
        jsonObject.getString("node_name"),
        jsonObject.getString("node_code"),
        jsonObject.getIntValue("node_seq"),
        jsonObject.getIntValue("node_type"),
        jsonObject.getString("sampl_time"),
        jsonObject.getString("nb_sn"),
        jsonObject.getString("nb_imei"),
        jsonObject.getString("nb_device_id"),
        jsonObject.getString("node_path"),
        jsonObject.getIntValue("delay"),
        parseChildNodes(jsonObject.getJSONArray("child_nodes"))
    )
}
